import requests

# 基础 URL
BASE_URL = "https://httpbin.org"

# 用户名和密码
USER = "testuser"
PASSWORD = "testpass"

# GET: /basic-auth/{user}/{passwd}
# Prompts the user for authorization using HTTP Basic Auth.
# parameters: user, passwd; string, (path)
# responses: 200(Successful authentication), 401(Unsuccessful authentication)
def basic_auth():
    # 1. 测试有效的用户名和密码
    valid_url = f"{BASE_URL}/basic-auth/{USER}/{PASSWORD}"
    valid_response = requests.get(valid_url, auth=(USER, PASSWORD))
    print("Valid Auth Response:", valid_response.json())

    # 2. 测试无效的用户名和密码
    invalid_url = f"{BASE_URL}/basic-auth/{USER}/{PASSWORD}"
    invalid_response = requests.get(invalid_url, auth=("wronguser", "wrongpass"))
    print("Invalid Auth Response:", invalid_response.status_code)

# 运行测试
basic_auth()